package com.edu.system.domain;

import cn.hutool.core.date.DateUtil;
import com.edu.common.annotation.Excel;
import com.edu.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 卡管理对象 t_card
 *
 * @author xxxx
 * @date 2023-12-17
 */
@Data
public class TCard extends BaseEntity {
    private static final long serialVersionUID = 1L;
    public static final int type_student = 0;
    public static final int type_teacher = 1;

    /**
     * 自增id
     */
    private Long id;

    /**
     * 持有人
     */
    @Excel(name = "姓名")
    @NotBlank(message = "姓名不能为空")
    private String owner;

    /**
     * 教育ID
     */
    @Excel(name = "教育ID")
    @NotBlank(message = "教育ID不能为空")
    private String ownerId;

    /**
     * 卡号
     */
    @Excel(name = "卡号")
    @NotBlank(message = "卡号不能为空")
    private String cardNo;

    private Long classId;

    private String className;

    private String generation;

    private String lineNo;

    /**
     * 余额 单位元
     */
    private Float balance;

    /**
     * 有效期开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
    @NotNull(message = "开始时间不能为空")
    private Date expireFrom;

    /**
     * 有效期截止时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
    @NotNull(message = "结束时间不能为空")
    private Date expireTo;

    /**
     * 卡类型(学生/教师)
     */
    private Integer type;

    /**
     * 状态(正常/无效)
     */
    private Integer status;

    private Integer isDeleted=0;

    public boolean isValidCard(){
        if (status==null || expireFrom==null || expireTo==null){
            return true;
        }
        Date now = new Date();
        if (status.equals(1)){
            return false;
        }
        return now.after(expireFrom) && now.before(expireTo);
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("owner", getOwner())
                .append("ownerId", getOwnerId())
                .append("cardNo", getCardNo())
                .append("expireFrom", getExpireFrom())
                .append("expireTo", getExpireTo())
                .append("type", getType())
                .append("status", getStatus())
                .toString();
    }
}
